/*
 Copyright (c) 2008 TPSi
 Alex Iskander
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 
 */

#ifndef BINDABLE_BINDABLE_RULES_EQUALITYRULE_H_
#define BINDABLE_BINDABLE_RULES_EQUALITYRULE_H_

#include "../Rule.h"
#include "../Bound.h"

namespace Bind
{
	/**
	 \class EqualityRule
	 \brief Represents a rule which checks equality. 
	 
	 The equality check is between two properties of the rule, property Left and
	 property Right. If Left is equal to Right, the return value is greater than
	 .5; otherwise, the return value is less.
	 */
	template <typename PropertyType>
	class EqualityRule : public Rule
	{
	public:
		/**
		 \fn EqualityRule();
		 \brief Default constructor.
		 */
		EqualityRule();
		
		
		/**
		 \fn EqualityRule(Selector *left, Selector *value);
		 \brief Creates a rule from a selector and a value.
		 */
		EqualityRule(Selector *left, Selector *value);
		
		/**
		 \fn EqualityRule(Selector *left, PropertyType value);
		 \brief Creates a rule from a selector and a value.
		 */
		EqualityRule(Selector *left, PropertyType value);
		
		/**
		 \fn EqualityRule(PropertyType left, Selector *value);
		 \brief Creates a rule from a selector and a value.
		 */
		EqualityRule(PropertyType left, Selector *value);
		
		/**
		 \fn EqualityRule(PropertyType left, PropertyType value);
		 \brief Creates a rule from a selector and a value.
		 */
		EqualityRule(PropertyType left, PropertyType value);
		
		
		/**
		 \fn evaluate();
		 \brief Evaluates and returns a score.
		 */
		double evaluate();
		
		
		Bound<PropertyType> left;
		Bound<PropertyType> right;
		
	};
	
	template <typename PropertyType>
	EqualityRule<PropertyType>::EqualityRule()
	{
		this->addProperty("left", &this->left);
		this->addProperty("right", &this->right);
	}
	
	template <typename PropertyType>
	EqualityRule<PropertyType>::EqualityRule(Selector *left, Selector *right)
	{
		this->left.bindTo(left);
		this->right.bindTo(right);
		this->addProperty("left", &this->left);
		this->addProperty("right", &this->right);
	}
	
	template <typename PropertyType>
	EqualityRule<PropertyType>::EqualityRule(Selector *left, PropertyType right)
	{
		this->left.bindTo(left);
		this->right = right;
		this->addProperty("left", &this->left);
		this->addProperty("right", &this->right);
	}
	
	template <typename PropertyType>
	EqualityRule<PropertyType>::EqualityRule(PropertyType left, Selector *right)
	{
		this->left = left;
		this->right.bindTo(right);
		this->addProperty("left", &this->left);
		this->addProperty("right", &this->right);
	}
	
	template <typename PropertyType>
	EqualityRule<PropertyType>::EqualityRule(PropertyType left, PropertyType right)
	{
		this->left = left;
		this->right = right;
		this->addProperty("left", &this->left);
		this->addProperty("right", &this->right);
	}
	
	template<typename PropertyType> double
	EqualityRule<PropertyType>::evaluate()
	{
		if (left.get() == right.get())
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	

}

#endif
